# -*- coding: utf-8 -*-
# @Time    : 2020/10/22 16:33
# @Author  : Leo
# @FileName: handler.py
# @Software: PyCharm

import json
import tornado.web
from modules.user.user_manage import UserManager
from handlers.base_handler import BaseHandler


class UserHandler(tornado.web.RequestHandler):
    def set_default_headers(self):
        self.set_header('Access-Control-Allow-Origin', '*')
        self.set_header('Access-Control-Allow-Headers', '*')
        self.set_header('Access-Control-Max-Age', 1000)
        # self.set_header('Content-type', 'application/json')
        self.set_header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
        self.set_header('Access-Control-Allow-Headers',  # '*')
                        'authorization, Authorization, Content-Type, Access-Control-Allow-Origin, Access-Control-Allow-Headers, X-Requested-By, Access-Control-Allow-Methods')
    def options(self, loginName):
        pass
    def get(self, loginName):
        '''
        根据用户名获取用户信息
        @return:
        '''
        user_info  = UserManager().get_by_loginName(loginName)
        if user_info:
            self.write(json.dumps(user_info[0]))
        else:
            self.write({"code":401,
                        "message":"用户不存在"})